package com.tdkj.action.backstage.decorate;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.tdkj.action.BaseAction;
import com.tdkj.model.decorate.BeanModuleCustom;
import com.tdkj.service.decorate.IBeanModuleCustomService;


public class ModuleCustomAction extends BaseAction {
    
	private IBeanModuleCustomService moduleCustomService;
	
	private BeanModuleCustom custom ;
	
	private Long moduleId;
	
	
	public String execute() {
		
		String hql = "select bean from " + BeanModuleCustom.class.getName() + " as bean where bean.module.id='"+moduleId+"' order by bean.id";
		Query query = this.createQuery(hql);
		this.queryByPage(query, "moduleCustomAction.action", 10);
		return "success";
	}
	
	public String add() {
		moduleCustomService.save(custom);
		return execute();
	}
	
	public String update() {
		moduleCustomService.saveOrUpdate(custom, BeanModuleCustom.class);
		return execute();
	}

	public String delete() {
		moduleCustomService.delete(custom.getId(), BeanModuleCustom.class);
		return execute();
	}
	
	public String edit() {
		custom = moduleCustomService.findById(custom.getId(), BeanModuleCustom.class);
		return "edit";
	}

	public BeanModuleCustom getCustom() {
		return custom;
	}

	public void setCustom(BeanModuleCustom custom) {
		this.custom = custom;
	}

	public Long getModuleId() {
		return moduleId;
	}

	public void setModuleId(Long moduleId) {
		this.moduleId = moduleId;
	}

	@Resource
	public void setModuleCustomService(IBeanModuleCustomService moduleCustomService) {
		this.moduleCustomService = moduleCustomService;
	}


	
	
}
